#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
long long a[10000000];
int a1[10000000];
long long ans=0,n;
int dfs(long long x)
{
	long long i,k,score=0;
	if(x==n)
	{
	for(i=n;i>=1;i--)
	{
	k=i-1;
	while(a1[i]!=a1[k]&&k!=0)
	  k--;
	if(k==-1)
	  return 0;
	if(a[i]==a[k])
	  score=score+a[i];
	}
	ans=max(ans,score);
	return 0;
    }
	else
	for(i=x;i<=n;i++)
	{
	dfs(i+1);
	a1[i]=1;
	dfs(i+1);
	} 
    return 0;
}
int main()
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	long long i,j,t;
	cin>>t;
	for(i=1;i<=t;i++)
	{
		memset(a,0,sizeof(a));
		cin>>n;
		for(j=1;j<=n;j++)
		  cin>>a[j];
		dfs(1);
		cout<<ans;
	}
	return 0;
}
